//
//  LRMainController.swift
//  LRWeibo
//
//  Created by Ruihaha on 16/9/22.
//  Copyright © 2016年 macbook air . All rights reserved.
//

import UIKit

class LRMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //MARK: KVC赋值的方式修改系统tabbar
        let customBar = LRTabBar()
        customBar.composeClickClosure={
        print("~~~~~~~compose按钮被点击了~~~~~~")
        }
        self .setValue(customBar, forKey: "tabBar")
        
        addChildViesControllers()
        print(childViewControllers)
    }

    //MARK: 添加子控制器
    private func addChildViesControllers(){
        
    addChildController(viewController: LRHomeController(), titleName: "首页", itemImageName: "tabbar_home")
    addChildController(viewController: LRMessageController(), titleName: "消息", itemImageName: "tabbar_message_center")
    addChildController(viewController: LRDiscoverController(), titleName: "发现", itemImageName: "tabbar_discover")
    addChildController(viewController: LRProfileController(), titleName: "我", itemImageName: "tabbar_profile")
        
    }
    
    private func addChildController(viewController vc : UIViewController,titleName title:String,itemImageName imageName:String){
        
     
        vc.navigationItem.title = title;
        vc.tabBarItem.title = title;
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 11)], for: .normal)
        
        let nav = LRNaviController(rootViewController: vc)
        self.addChildViewController(nav)

    }

}
